package com.onemile.app;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.onemile.app.R;
import com.onemile.app.base.BaseUI;
import com.onemile.controls.AdpLV_Account;
import com.onemile.entity.PubConst;
import com.onemile.entity.Session;
import com.onemile.entity.PubConst.ActivityCode;
import com.onemile.entity.model.EStandardListViewItem;

public class UIAccount extends BaseUI
{

   private ListView mListView;
   private TextView txtUserName;
   private TextView txtMoney;
   private TextView txtPoint;
   private Button btnLogout;

   private void InitControls()
   {
	  mListView = (ListView) findViewById(R.id.list1_account);
	  txtUserName = (TextView) findViewById(R.id.txtUserName_account);
	  txtPoint = (TextView) findViewById(R.id.txtPoint_account);
	  txtMoney = (TextView) findViewById(R.id.txtMoney_account);
	  btnLogout = (Button) findViewById(R.id.btnLogout_account);

	  // txtUserName.setText(Session.getInstance().getUserName());
	  // txtPoint.setText(Session.getInstance().getUserInfo().getPoint());
	  // txtMoney.setText(Session.getInstance().getUserInfo().getMoney());

	  mListView.setOnItemClickListener(new OnItemClickListener()
	  {

		 @Override
		 public void onItemClick(AdapterView<?> parent, View view, int position, long id)
		 {
			Intent intent = new Intent();
			switch (position)
			{
			   case 0:// 我的订单

				  break;
			   case 1:// 历史订单

				  break;
			   case 2:// 我的收藏

				  intent.setClass(UIAccount.this, UIFavoriteList.class);
                  startActivity(intent);
				  break;
			   case 3:// 我的优惠

				  break;
			   case 4:// 我的抵用券

				  break;
			   case 5:// 管理收货地址
				  intent.setClass(UIAccount.this, UISettlementAddress.class);
				  intent.putExtra(PubConst.Intent_Key.IS_ADDRESS_MANAGER, true);
				  startActivity(intent);
				  break;
			}
			
		 }
	  });

	  btnLogout.setOnClickListener(new View.OnClickListener()
	  {
		 @Override
		 public void onClick(View v)
		 {
			Session.getInstance().Logout();
			Intent intent = new Intent();
			intent.setClass(UIAccount.this, UIHome.class);
			intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
			startActivity(intent);
			finish();
		 }
	  });
   }

   private void InitListViewMenu()
   {
	  ArrayList<EStandardListViewItem> list = new ArrayList<EStandardListViewItem>();
	  // 0==我的订单
	  list.add(new EStandardListViewItem(R.drawable.account_orders, getString(R.string.account_myorder)));
	  // 1==历史订单
	  list.add(new EStandardListViewItem(R.drawable.account_orders, getString(R.string.account_history)));
	  // 2==我的收藏
	  list.add(new EStandardListViewItem(R.drawable.account_favorites, getString(R.string.account_myfavorite)));
	  // 3==我的优惠
	  list.add(new EStandardListViewItem(R.drawable.account_sale, getString(R.string.account_preferential)));
	  // 4==我的抵用券
	  list.add(new EStandardListViewItem(R.drawable.account_quan, getString(R.string.account_vouchers)));
	  // 5==管理收货地址
	  list.add(new EStandardListViewItem(R.drawable.account_quan, getString(R.string.account_address)));

	  AdpLV_Account adp = new AdpLV_Account(list, this);
	  mListView.setAdapter(adp);
   }

   @Override
   protected void onCreateOverride(Bundle savedInstanceState)
   {
	  InitControls();
	  InitListViewMenu();

   }

   @Override
   public int SetContentViewLayoutResId()
   {
	  return R.layout.account;
   }

   @Override
   public void SetTopToolbar(TextView topTxt, ImageView leftImBtn, ImageView rightImgBtn, RelativeLayout rightRay, TextView cartNum)
   {
	  topTxt.setText(getString(R.string.title_account));
	  SetTopSytle(2);

   }

}
